#ifdef _WIN32
#include <windows.h>
#include <process.h>
#include <mutex>
#else
#include <pthread.h>
#include <unistd.h>
#include <mutex>
#endif
namespace unix_BlockInCriticalSection
{
#ifndef _WIN32
	void pthread_lock_example(pthread_mutex_t* m)
	{
		pthread_mutex_lock(m); // note: entering critical section here
		sleep(10); // warn: Call to blocking function 'sleep' inside of critical section
		pthread_mutex_unlock(m);
	}

	void overlapping_critical_sections(mtx_t* m1, std::mutex& m2) {
		std::lock_guard lg{ m2 }; // note: entering critical section here
		mtx_lock(m1); // note: entering critical section here
		sleep(10); // warn: Call to blocking function 'sleep' inside of critical section
		mtx_unlock(m1);
		sleep(10); // warn: Call to blocking function 'sleep' inside of critical section
				   // still inside of the critical section of the std::lock_guard
	}

	void trylock_example(pthread_mutex_t* m) {
		if (pthread_mutex_trylock(m) == 0) { // assume trylock always succeeds
			sleep(10); // warn: Call to blocking function 'sleep' inside of critical section
			pthread_mutex_unlock(m);
		}
		else {
			sleep(10); // false positive: Incorrect warning about blocking function inside critical section.
		}
	}
#endif
}